package com.android.canvasproject.model.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;

import com.android.canvasproject.enums.LocalCreationEnum;
import com.android.canvasproject.enums.SynchronizedEnum;

public abstract class GenericEntity implements Serializable {
	
	private static final long serialVersionUID = -7685552670739465366L;
	
	private long idICS;

	private Date creationDate;
	
	private Timestamp lastSync;
	
	private Timestamp lastNotification;
	
	private LocalCreationEnum localCreation;
	
	private SynchronizedEnum isSynchronized;
	
	protected GenericEntity() {
		creationDate = new Date();
		localCreation = LocalCreationEnum.LOCAL_INTERFACE_MOBILE;
		isSynchronized = SynchronizedEnum.NOT_SYNCHRONIZED;
	}
	
	public void entityStruture(Map<String, Object> map) throws ParseException {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());

		this.setIdICS(map.get("id_ics") == null ? 0l : Long.parseLong(String.valueOf(map.get("id_ics"))));
		this.setLocalCreation(LocalCreationEnum.values()[(Integer) map.get("local_creation")]);
		this.setIsSynchronized(SynchronizedEnum.values()[(Integer) map.get("is_synchronized")]);
		this.setCreationDate(map.get("creation_date") == null ? null : format.parse((String) map.get("creation_date")));
		this.setLastSync((Timestamp) (map.get("last_sync") == null ? null : format.parse((String) map.get("last_sync"))));
		this.setLastNotification((Timestamp) (map.get("last_notification") == null ? null : format.parse((String) map.get("last_notification"))));
	}

	public long getIdICS() {
		return idICS;
	}

	public void setIdICS(long idICS) {
		this.idICS = idICS;
	}

	public Date getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	public Timestamp getLastSync() {
		return lastSync;
	}

	public void setLastSync(Timestamp lastSync) {
		this.lastSync = lastSync;
	}

	public Timestamp getLastNotification() {
		return lastNotification;
	}

	public void setLastNotification(Timestamp lastNotification) {
		this.lastNotification = lastNotification;
	}

	public LocalCreationEnum getLocalCreation() {
		return localCreation;
	}

	public void setLocalCreation(LocalCreationEnum localCreation) {
		this.localCreation = localCreation;
	}

	public SynchronizedEnum getIsSynchronized() {
		return isSynchronized;
	}

	public void setIsSynchronized(SynchronizedEnum isSynchronized) {
		this.isSynchronized = isSynchronized;
	}
}